<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/5/21 0021
 * Time: 17:28
 */

namespace Admin\Controller;


class StoreController extends AdminController
{
    public function index()
    {
        $nickname       =   I('nickname');
        $map['status']  =   array('egt',0);
        $map['title']    =   array('like', '%'.(string)$nickname.'%');

        $list   = $this->lists('ShopStore', $map);
        int_to_string($list);
        foreach ($list as &$v){
            $v['shop_name'] = M('shop')->where(['id'=>$v['sid']])->getField('title');
        }
        $this->assign('_list', $list);
        $this->meta_title = '店铺管理';
        $this->display();
    }
    public function add()
    {
        $id = I('id');
        if($id==''||empty($id))$this->error('店铺标识不存在');
        $data['title'] = I('title');
        $data['thumb'] = I('thumb');
        $data['extra'] = I('extra');
        $data['area'] = I('area');
        $data['address'] = I('address');
        $data['describe'] = I('describe');
        $data['lng'] = I('lng');
        $data['lat'] = I('lat');
        M('ShopStore')->where(['id'=>$id])->save($data);
        $arr['title'] = I('ftitle');
        $arr['up_num'] = I('up_num');
        $arr['in_num'] = I('in_num');
        foreach ($arr as $v){
            if($v =='' ||empty($v)){
                $this->success('执行成功');
            }
        }
        $arr['sid'] = $id;
        $arr['status'] = 1;
        M('ShopStoreScreen')->add($arr);
        $this->success('执行成功');
    }
    public function edit()
    {
        $id = I('get.id');

        empty($id) && $this->error('参数不能为空！');
        $data = M('ShopStore')->field(true)->find($id);
        if(!empty($data)) {
            $data['screen'] = M('ShopStoreScreen')->field(true)->select();
        }
        $this->assign('info',$data);
        $this->meta_title = '编辑店铺';
        $this->display();
    }

    public function changeStatus($method=null)
    {
        $id = array_unique((array)I('id',0));
        $id = is_array($id) ? implode(',',$id) : $id;
        if ( empty($id) ) {
            $this->error('请选择要操作的数据!');
        }
        $map['id'] =   array('in',$id);
        switch ( strtolower($method) ){
            case 'forbid':
                $this->forbid('ShopStore', $map );
                break;
            case 'resume':
                $this->resume('ShopStore', $map );
                break;
            case 'delete':
                $this->delete('ShopStore', $map );
                break;
            default:
                $this->error('参数非法');
        }
    }
}